package com.white.databasesbackup.dao.impl;

import com.white.databasesbackup.dao.DatabasesBackupLogDao;
import com.white.databasesbackup.entity.DatabasesBackupLog;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * <p>
 *
 * </p>
 *
 * @author huangzy
 * @since 2022/5/6
 */
@Component
public class DatabasesBackupLogDaoImpl implements DatabasesBackupLogDao {

    @Resource
    private JdbcTemplate jdbcTemplate;

    @Override
    public void save(DatabasesBackupLog entity) {
        if (entity.getCreateTime() == null) {
            entity.setCreateTime(LocalDateTime.now());
        }
        String sql = "INSERT INTO databases_backup_log (`databases_name`, `table_name`, `count`, `delete_count`, `create_time`, `exec_status`, `fail_msg`) VALUES (?,?,?,?,?,?,?)";
        jdbcTemplate.update(sql,entity.getDatabasesName(),entity.getTableName(),entity.getCount() == null ? 0 : entity.getCount(),entity.getDeleteCount() == null ? 0 : entity.getDeleteCount(),entity.getCreateTime(),entity.getExecStatus(),entity.getFailMsg());
    }
}
